#!/usr/bin/env bash
set -euo pipefail

# 仅启动 Docker 依赖（postgres + redis + browserless + rsshub）

ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"

command_exists() {
    command -v "$1" >/dev/null 2>&1
}

docker_compose() {
    if docker compose version >/dev/null 2>&1; then
        docker compose "$@"
    elif command_exists docker-compose; then
        docker-compose "$@"
    else
        echo "❌ 未检测到 docker compose，请安装 Docker Compose v2 或 docker-compose"
        exit 1
    fi
}

if ! command_exists docker; then
    echo "❌ 未检测到 docker，无法启动依赖"
    exit 1
fi

echo "[docker] 启动 postgres / redis / browserless / rsshub ..."
(cd "${ROOT_DIR}" && docker_compose up -d postgres redis browserless rsshub)
echo "[docker] 已启动"
